using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace ZYCommon
{
    class ZYTime
    {
        public static string DoHttpRequest(string strWWWAddress)
        {
            string strResult = "";
            HttpWebRequest oRequest = null;
            Stream oInStream = null;
            HttpWebResponse oRespons = null;
            StreamReader readStream = null;
            Encoding oEncoding = Encoding.UTF8;
            try
            {
                oRequest = (HttpWebRequest)WebRequest.Create(strWWWAddress);
                oRequest.Method = "GET";
                oRespons = (HttpWebResponse)oRequest.GetResponse();
                readStream = new StreamReader(oRespons.GetResponseStream(), oEncoding);
                strResult = readStream.ReadToEnd();
                readStream.Close();
                readStream = null;
                oRespons.Close();
                oRespons = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (oInStream != null)
                {
                    oInStream.Close();
                }
                if (readStream != null)
                {
                    readStream.Close();
                }
                if (oRespons != null)
                {
                    oRespons.Close();
                }
            }
            return strResult;
        }

        public static DateTime GetServerTime()
        {
            string strData = DateTime.Now.ToString("yyyyMMddHHmmss").PadRight(14, '0');
            return new DateTime(Convert.ToInt32(strData.Substring(0, 4)), Convert.ToInt32(strData.Substring(4, 2)), Convert.ToInt32(strData.Substring(6, 2)), Convert.ToInt32(strData.Substring(8, 2)), Convert.ToInt32(strData.Substring(10, 2)), Convert.ToInt32(strData.Substring(12, 2)));
        }
    }
}
